﻿Array.prototype.filter = function(fn, scope) {
    if (this.length !== 0 && typeof fn === 'function') {
        var _len = this.length;
        var rs = [];
        for (var i = 0; i < _len; i++) {
            if (fn.call(scope || this, this[i], i, this)) rs.push(this[i]);
        }
        return rs;
    }
    return [];
};

Ext.apply(Sail.widget.ext.combox.prototype, {
    fieldValue: "id",
    fieldText: "name",
    root: "dataset.item",
    set_data: function(t, v) {
        if ( !! t) this.setText(t);
        this.el.value = v;
        this.el.el.removeClass(this.el.invalidClass);
        this.el.fireEvent('aftersetvalue', this.el, {},
        t, v);
    }
});

Ext.apply(Sail.widget.ext.calendar.prototype, {
    set_current_date: function() {
        this.el.setValue(new Date());
    }
});

Ext.apply(Sail.widget.ext.form.prototype, {
    travel_childs: function(fn, filter) {
        var _this = this;
        _children = this.ownerGroup.filter(function(elem, index) {
            if (!elem.owner) return false;
            return (elem.owner.executor === this.name);
        },
        _this);

        if (filter && typeof filter === "string") {
            filter = [filter];
            _children = _children.filter(function(elem, index) {
                return ! filter.indexOf(elem.name);
            });
        }

        _len = _children.length;
        var flag = (typeof fn === "string" && ["disable", "enable", "hide", "show"].indexOf(fn));
        for (var i = 0; i < _len; i++) {
            flag && _children[i][fn]();
            if (!flag && typeof fn === "function") fn.call(_children[i], _children[i], i);
        }
    }
});
Ext.isArray = function(v) {
    return Object.prototype.toString.apply(v) === '[object Array]';
};

Ext.apply(Sail, {
    isFunction: function(v) {
        return Object.prototype.toString.apply(v) === '[object Function]';
    },
    jqextend: function() { // copy reference to target object
        var target = arguments[0] || {},
        i = 1,
        length = arguments.length,
        deep = false,
        options,
        name,
        src,
        copy;

        if (typeof target === "boolean") {
            deep = target;
            target = arguments[1] || {}; // skip the boolean and the target
            i = 2;
        }

        // Handle case when target is a string or something (possible in deep copy)
        if (typeof target !== "object" && ! Sail.isFunction(target)) {
            target = {};
        }

        // extend jQuery itself if only one argument is passed
        if (length === i) {
            target = this; --i;
        }

        for (; i < length; i++) { // Only deal with non-null/undefined values
            if ((options = arguments[i]) != null) { // Extend the base object
                for (name in options) {
                    src = target[name];
                    copy = options[name];

                    // Prevent never-ending loop
                    if (target === copy) {
                        continue;
                    }

                    // Recurse if we're merging object values
                    if (deep && copy && typeof copy === "object" && ! copy.nodeType) {
                        target[name] = Sail.jqextend(deep, src || (copy.length != null ? [] : {}), copy);

                        // Don't bring in undefined values
                    }
                    else if (copy !== undefined) {
                        target[name] = copy;
                    }
                }
            }
        }

        // Return the modified object
        return target;
    },
    isArray: function(v) {
        return Object.prototype.toString.apply(v) === '[object Array]';
    },
    isNumber: function(v) {
        return typeof v === 'number' && isFinite(v);
    },
    splat: function(obj) {
        if (!obj || obj.constructor != Array) obj = [obj];
        return obj;
    },
    isEmpty: function(v, allowBlank) {
        return v === null || v === undefined || ((Sail.isArray(v) && (v.length === 0 || ! v.length))) || (!allowBlank ? v === '': false);
    },
    postData: function(_url, postData, successFn, errorFn, source) {
        if (_url == "") {
            Ext.Msg.alert("信息", "没有找到url！");
            return;
        }
        Ext.Ajax.request({
            url: _url,
            method: 'POST',
            params: postData,
            success: function(action) {
                var getResponse = Ext.decode(action.responseText);
                var flag = getResponse.dataset.response.success;
                if (typeof successFn == "function") {
                    successFn.call(this, flag, getResponse, source);
                }
                else {
                    Ext.Msg.alert('提示：', successInfo);
                    return true;
                }
            },
            failure: function(action) {
                var _status = action.status;
                if (typeof errorFn == "function") {
                    errorFn.call(this, false, _status);
                }
                else {
                    Ext.Msg.alert('提示：', '提交数据失败！');
                    return false;
                }
            }
        });
    },
    createDiv: function(config) {
        var div = document.createElement("DIV");
        Sail.apply(div, config);
        document.body.insertBefore(div, null);
        return div;
    }
});
/*
flexable
----------------------------------------------------------------------------------------------------
*/

if (Object.prototype.toJSONString) {
    delete Object.prototype.toJSONString;
    delete Array.prototype.toJSONString;
    delete Boolean.prototype.toJSONString;
    delete Date.prototype.toJSONString;
    delete Number.prototype.toJSONString;
}
Ext.override(Sail.frame, {
    business2JSON: function() {
        this.saveString = Ext.encode(this.businessData);
        return this.saveString;
    }
});
Ext.override(Sail.widget.ext.treeChoice, {
    reSetOpenFn: function() {
        var tmpConfig = {};
        Sail.apply(tmpConfig, this.treeConfig);
        tmpConfig.selectedNodes = this.getValue();

        var str = Ext.decode(tmpConfig);
        this.openFn = this.fnTemplet.replace("{0}", str);
        this.el.openFn = this.openFn;
    },
    createWidgetElement: function() {

        var box = this.createElStructure();

        if (this.treeConfig != undefined) {
            var str = Ext.decode(this.treeConfig);
            this.openFn = this.fnTemplet.replace("{0}", str);
        }
        var _config = {
            readOnly: true,
            blankText: "未选择...",
            width: this.boxWidth,
            openUrl: this.openUrl,
            openFn: this.openFn,
            showValue: (this.text) ? this.text: "text",
            dataValue: (this.value) ? this.value: "id",
            renderTo: box
        };

        if (this.allowBlank != undefined) _config.allowBlank = this.allowBlank;
        if (this.openWidth != undefined) _config.openWidth = this.openWidth;
        if (this.openHeight != undefined) _config.openHeight = this.openHeight;
        if (this.commonParameter != undefined) _config.commonParameter = this.commonParameter;
        this.el = new Ext.form.SelectField(_config);

        if (this.disabled) this.el.disable();
        this.el.focus();
        if (this.maxLength) this.el.el.dom.maxLength = this.maxLength;
        this.el.on('afterclick', function() {
            this.reSetOpenFn();
        },
        this);
    }
});
/*--------------------------------------------------------------------------------------------------*/
window.HighchartsAdapter = {
    getAjax: function(url, callback) {
        Ext.Ajax.request({
            url: url,
            success: function(response) {
                callback(response.responseText);
            }
        });
    },
    hyphenate: function(str) {
        return str.replace(/([A-Z])/g, function(a, b) {
            return '-' + b.toLowerCase();
        });
    },
    addEvent: function(el, event, fn) {
        var xel = Ext.get(el);
        if (xel) xel.addListener(event, fn);
    },
    fireEvent: function(el, event, eventArguments, defaultFunction) { // if fireEvent is not available on the object, there hasn't been added
        if (el.fireEvent) el.fireEvent(event, eventArguments); // fire the default if it is passed and it is not prevented above
        if (defaultFunction) defaultFunction(event);
    },
    animate: function(el, params, options) { //jQuery(el).animate(params, options);
        var element = Ext.fly(el);
        var opt = {};
        var duration = 1.5;
        var callback = null;
        for (var p in params) {
            opt[p] = {
                to: (params[p] + "").replace("px", "")
            };
        }
        for (var l in options) {
            if (l === "complete") callback = options[l];
        }
        element.animate(opt, duration, callback, "easeOut", "run");
    },
    each: function(arr, fn) {
        for (var i = 0, len = arr.length; i < len; i++) if (fn.call(arr[i], arr[i], i, arr) === false) return i;
    },
    map: function(arr, fn) {
        var results = [];
        if (arr) for (var i = 0, len = arr.length; i < len; i++) {
            results[i] = fn.call(arr[i], arr[i], i, arr);
        }
        return results;
    },
    merge: function() {
        var args = arguments;
        return Sail.jqextend(true, null, args[0], args[1], args[2], args[3]);
    },
    grep: function(arr, fn) {
        return arr.filter(fn);
    }
};

var merge = window.HighchartsAdapter["merge"];
/*
----------------------------------------------------------------------------------------
*/
Sail.widget.ext.ux_chart = function(config) {
    this.title = "myReport";
    this.is_convert = true;
    this.drawTable = false;
    this.sub_title;
    this.url;
    this.theme = "grid";
    this.stacking = '';
    this.x_rotation = 0;
    this.y_rotation = 0;
    this.series_root = "dataset.report";
    this.xAxis_root = "dataset.categories";
    this.margin = Highcharts["defaultOptions"]["chart"]["margin"];
    this.is_legend = true;
    this.legend_layout = 'horizontal';
    this.xAxis = [];
    this.yAxis = []; //[{name:"",color:"",unit:""}]
    this.series = []; //[{name:"",type:"",data:[]}]
    this.formatter = function() {
        if (this.point && this.point.name && Sail.isEmpty(this.point.name)) return '<b>' + this.point.name + '</b><br/>' + this.y;
        else return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y;
    };
    /*以下参数为前台转换方法服务*/
    this.root = "";
    this.key_x = "";
    this.key_y = [];
    this.key_y_desc = [];
    this.l_name = "";
    this.series_type = {};
    this.serise_yaxis = {};
    this.legend_style = {
        left: '120px',
        bottom: 'auto',
        right: '50px',
        top: '5px'
    };
    Sail.widget.ext.ux_chart.superclass.constructor.call(this, config);
};

Ext.extend(Sail.widget.ext.ux_chart, Sail.widget, {
    defaultHeight: 400,
    defaultWidth: 800,
    defaultSeriesType: "line",
    initComponent: function() {},
    clean_config: function() {
        this.title = "myReport";
        this.is_convert = true;
        this.drawTable = false;
        this.sub_title;
        this.url = "";
        this.theme = "grid";
        this.stacking = '';
        this.is_legend = true;
        this.legend_layout = 'horizontal';
        this.x_rotation = 0;
        this.y_rotation = 0;
        this.margin = Highcharts["defaultOptions"]["chart"]["margin"];
        this.series_root = "dataset.report";
        this.xAxis_root = "dataset.categories";
        this.xAxis = [];
        this.yAxis = []; //[{name:"",color:"",unit:""}]
        this.series = []; //[{name:"",type:"",data:[]}]
        this.formatter = function() {
            if (this.point && this.point.name && ! Sail.isEmpty(this.point.name)) return '<b>' + this.point.name + '</b><br/>' + this.y;
            else return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y;
        };
        this.root = "";
        this.key_x = "";
        this.key_y = [];
        this.key_y_desc = [];
        this.l_name = "";
        this.series_type = {};
        this.serise_yaxis = {};
    },
    /*
        key_x :""
        key_y :[]
        key_y_desc:[]
        type : {y1 : "column",y2:"spine",y3:"areaspine" ...........}
        y_axis :{y1 :0,y2:1 ......}
    */
    data_parser: function(json_data, root, key_x, key_y, key_y_desc, l_name, series_type, y_axis) {
        var rs = Sail.splat(Sail.getSubObj(json_data, root));
        key_y = Sail.splat(key_y);
        var _len = rs.length;
        var series = [];
        var legend = [];
        var objs = {};
        var _x = [];
        var r;
        if (!rs[0]) return {
            xAxis: [],
            series: []
        };

        for (var i = 0; i < _len; i++) {
            r = rs[i];

            var p_x = r[key_x];
            _x.push(p_x);
            legend.push(r[l_name]);

            if (!objs[r[l_name]]) objs[r[l_name]] = {};
            for (var j = 0; j < key_y.length; j++) {
                var p_y = r[key_y[j]];

                if (!objs[r[l_name]][key_y[j]]) {
                    objs[r[l_name]][key_y[j]] = {};
                }
                objs[r[l_name]][key_y[j]][p_x] = parseFloat(p_y);
            }
        }
        _x = _x.distinct(); //.sort();
        //this.getOCD().style.width=120*(_x.length)>800?120*(_x.length):800;
        legend = legend.distinct();
        /* X 轴 null 值补全*/

        for (var p in objs) {
            for (var a in objs[p]) {
                var t = objs[p][a]; //{}
                var rs = [];
                for (var i = 0; i < _x.length; i++) {
                    if (!t[_x[i]]) {
                        rs.push(null);
                    }
                    else {
                        rs.push(t[_x[i]]);
                    }
                }
                objs[p][a] = rs;
            }
        }

        for (var i = 0; i < key_y.length; i++) {
            var t = key_y[i];
            for (var j = 0; j < legend.length; j++) {
                var l = legend[j];
                series.push({
                    name: l + (!Sail.isEmpty(key_y_desc[i]) ? "[" + key_y_desc[i] + "]": ""),
                    type: series_type[t],
                    yAxis: y_axis[t],
                    data: objs[l][t]
                });
            }
        }

        return {
            series: series,
            xAxis: _x
        };
    },
    getHeight: function() {
        return this.height || this.defaultHeight;
    },
    setHeight: function(height) {
        this.getOCD().style.height = height || this.getHeight();
    },
    getWidth: function() {
        return this.width || this.defaultWidth;
    },
    setWidth: function(width) {
        this.getOCD().style.width = width || this.getWidth();
    },
    getEl: function() {
        return this.el;
    },
    setTheme: function(theme) {
        this.theme = theme;
        Highcharts.setOptions(_THEMES[this.theme]);
    },
    getTheme: function() {
        return this.theme;
    },
    init_config: function(config) {
        if (!Sail.isEmpty(config)) Ext.apply(this, config);
        this.options = {};
        Highcharts.setOptions(_THEMES[this.theme]);
        this.options = {
            drawTable: this.drawTable,
            chart: {
                renderTo: this.getOCD(),
                margin: this.margin,
                defaultSeriesType: this.defaultSeriesType
            },
            credits: {
                enabled: false,
                href: "http://www.talkweb.com.cn",
                target: "_self",
                text: "talkweb.com.cn"
            },
            title: {
                text: this.title
            },
            subtitle: {
                text: this.sub_title
            },
            xAxis: [{
                categories: this.xAxis,
                labels: {
                    rotation: this.x_rotation || 0,
                    align: 'center',
                    style: {
                        font: 'normal 12px Verdana, sans-serif'
                    }
                }
            }],
            yAxis: ! Sail.isEmpty(this.yAxis) ? this.yAxis: {
                title: {
                    enabled: false,
                    text: ""
                }
            },
            tooltip: {
                enabled: true,
                formatter: this.formatter
            },
            legend: {
                layout: this.legend_layout,
                enabled: this.is_legend,
                backgroundColor: '#FFFFFF',
                style: this.legend_style
            },
            plotOptions: {
                column: {
                    dataLabels: {
                        rotation: this.y_rotation || 0,
                        enabled: this.y_rotation !== 0,
                        color: 'auto',
                        align: "center",
                        style: {
                            font: 'normal 9px "Trebuchet MS", Verdana, sans-serif'
                        }
                    },
                    pointWidth: null,
                    groupPadding: .1,
                    stacking: Sail.isEmpty(this.stacking) ? '': "normal"
                },
                area: {
                    stacking: 'percent',
                    lineColor: '#ffffff',
                    lineWidth: 1,
                    marker: {
                        lineWidth: 1,
                        lineColor: '#ffffff'
                    }
                }
            },
            series: this.series
        }; //if (Sail.isEmpty(this.legend_layout)) this.options.legend = Highcharts["defaultOptions"]["legend"];
        if (this.legend_layout === 'vertical') {
            this.options["legend"].style = {
                left: '120px',
                bottom: 'auto',
                right: 'auto',
                top: '20px'
            };
        }
        if (Sail.isArray(this.yAxis) && ! Sail.isEmpty(this.yAxis)) {
            var units_rs = {};
            this.options.yAxis = [];
            Ext.each(this.yAxis, function(el, i, s) {
                this.options.yAxis.push({
                    title: {
                        text: el.name,
                        margin: i > 0 ? 70 * i: 70,
                        style: {
                            color: el.color
                        }
                    },
                    labels: {
                        formatter: function() {
                            return this.value + el.unit || "";
                        },
                        style: {
                            color: el.color
                        }
                    },
                    opposite: i > 0 ? true: false
                });
                units_rs[i] = el.unit || "";
            },
            this);
            /*this.options.tooltip["formatter"] = function (){
                return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y + units_rs[this.series.options.yAxis];
            };*/
        }
        if (this.url) {
            var self = this;
            var mask = new Ext.LoadMask(Ext.getBody(),{msg:'Loading...'});
            mask.show();
            Sail.postData(this.url, {},
            function(flag, rs) {
                if (flag) {
                	mask.hide();
                    if (self.is_convert) {
                        var t = self.data_parser(rs, self.root, self.key_x, self.key_y, self.key_y_desc, self.l_name, self.series_type, self.serise_yaxis);
                        self.options.series = t["series"];
                        self.options.xAxis[0]["categories"] = t["xAxis"];
                        self.options.extraItems = t["extraItems"];
                    }
                    else {
                    	mask.hide();
                        self.xAxis = Sail.splat(Sail.getSubObj(rs, self.xAxis_root));
                        self.series = Sail.splat(Sail.getSubObj(rs, self.series_root));
                        self.options.xAxis[0]["categories"] = self.xAxis;
                        self.options.series = self.series;
                    }

                    self.el = new Highcharts.Chart(self.options);
								}
						});
        }
        else this.el = new Highcharts.Chart(this.options);
    },
    load: function(config, is_clean) {
        var this_obj = this;
        (function() {
            if (this_obj.el) {
                this_obj.el.destroy();
                delete this_obj.el;
            }
            if (is_clean === true) {
                this_obj.clean_config();
            }
        }).createSequence(function() {
            this.init_config(config);
        },
        this).defer(1);
    },
    createWidgetElement: function() {
        this.init_config();
    }
});
Sail.widget.ext.ux_chart.themes = {
    "default": {},
    grid: {
        colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4', "#8B8386", "#CD69C9", "#E3CF57", "#303030", "#C67171", "#7D9EC0"],
        chart: {
            backgroundColor: {
                linearGradient: [0, 0, 500, 500],
                stops: [[0, 'rgb(255, 255, 255)'], [1, 'rgb(240, 240, 255)']]
            },
            borderWidth: 0,
            plotBackgroundColor: 'rgba(255, 255, 255, .9)',
            plotShadow: true,
            plotBorderWidth: 1
        },
        title: {
            style: {
                color: '#000',
                font: 'bold 16px "Trebuchet MS", Verdana, sans-serif'
            }
        },
        subtitle: {
            style: {
                color: '#666666',
                font: 'bold 12px "Trebuchet MS", Verdana, sans-serif'
            }
        },
        xAxis: {
            gridLineWidth: 1,
            lineColor: '#000',
            tickColor: '#000',
            labels: {
                style: {
                    color: '#000',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            alternateGridColor: null,
            minorTickInterval: 'auto',
            lineColor: '#000',
            lineWidth: 1,
            tickWidth: 1,
            tickColor: '#000',
            labels: {
                style: {
                    color: '#000',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                }
            }
        },
        legend: {
            itemStyle: {
                font: '9pt Trebuchet MS, Verdana, sans-serif',
                color: 'black'
            },
            itemHoverStyle: {
                color: '#039'
            },
            itemHiddenStyle: {
                color: 'gray'
            }
        },
        credits: {
            style: {
                right: '10px'
            }
        },
        labels: {
            style: {
                color: '#99b'
            }
        }
    },
    minimal: {
        colors: ["#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE", "#DB843D", "#92A8CD", "#A47D7C", "#B5CA92", "#8B8386", "#CD69C9", "#E3CF57", "#303030", "#C67171", "#7D9EC0"],
        chart: {
            backgroundColor: null,
            borderWidth: 0,
            plotBackgroundColor: null,
            plotShadow: false,
            plotBorderWidth: 0
        },
        title: {
            style: {
                color: '#3E576F',
                font: '16px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
            }
        },
        subtitle: {
            style: {
                color: '#6D869F',
                font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
            }
        },
        xAxis: {
            gridLineWidth: 0,
            lineColor: '#C0D0E0',
            tickColor: '#C0D0E0',
            labels: {
                style: {
                    color: '#666',
                    fontWeight: 'bold'
                }
            },
            title: {
                style: {
                    color: '#6D869F',
                    font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
                }
            }
        },
        yAxis: {
            alternateGridColor: null,
            minorTickInterval: null,
            lineWidth: 0,
            tickWidth: 0,
            labels: {
                style: {
                    color: '#666',
                    fontWeight: 'bold'
                }
            },
            title: {
                style: {
                    color: '#6D869F',
                    font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
                }
            }
        },
        legend: {
            itemStyle: {
                color: '#3E576F'
            },
            itemHoverStyle: {
                color: 'black'
            },
            itemHiddenStyle: {
                color: 'silver'
            }
        },
        credits: {
            style: {
                right: '50px'
            }
        },
        labels: {
            style: {
                color: '#3E576F'
            }
        }
    },
    gray: {
        colors: ["#DDDF0D", "#7798BF", "#55BF3B", "#DF5353", "#aaeeee", "#ff0066", "#eeaaee", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee", "#8B8386", "#CD69C9", "#E3CF57", "#303030", "#C67171", "#7D9EC0"],
        chart: {
            backgroundColor: {
                linearGradient: [0, 0, 0, 400],
                stops: [[0, 'rgb(96, 96, 96)'], [1, 'rgb(16, 16, 16)']]
            },
            borderWidth: 0,
            borderRadius: 15,
            plotBackgroundColor: null,
            plotShadow: false,
            plotBorderWidth: 0
        },
        title: {
            style: {
                color: '#FFF',
                font: '16px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
            }
        },
        subtitle: {
            style: {
                color: '#DDD',
                font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
            }
        },
        xAxis: {
            gridLineWidth: 0,
            lineColor: '#999',
            tickColor: '#999',
            labels: {
                style: {
                    color: '#999',
                    fontWeight: 'bold'
                }
            },
            title: {
                style: {
                    color: '#AAA',
                    font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
                }
            }
        },
        yAxis: {
            alternateGridColor: null,
            minorTickInterval: null,
            gridLineColor: 'rgba(255, 255, 255, .1)',
            lineWidth: 0,
            tickWidth: 0,
            labels: {
                style: {
                    color: '#999',
                    fontWeight: 'bold'
                }
            },
            title: {
                style: {
                    color: '#AAA',
                    font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
                }
            }
        },
        legend: {
            itemStyle: {
                color: '#CCC'
            },
            itemHoverStyle: {
                color: '#FFF'
            },
            itemHiddenStyle: {
                color: '#333'
            }
        },
        credits: {
            style: {
                right: '50px'
            }
        },
        labels: {
            style: {
                color: '#CCC'
            }
        },
        tooltip: {
            backgroundColor: {
                linearGradient: [0, 0, 0, 50],
                stops: [[0, 'rgba(96, 96, 96, .8)'], [1, 'rgba(16, 16, 16, .8)']]
            },
            borderWidth: 0,
            style: {
                color: '#FFF'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    color: '#CCC'
                },
                marker: {
                    lineColor: '#333'
                }
            },
            spline: {
                marker: {
                    lineColor: '#333'
                }
            },
            scatter: {
                marker: {
                    lineColor: '#333'
                }
            }
        },
        toolbar: {
            itemStyle: {
                color: '#CCC'
            }
        },

        // special colors for some of the
        legendBackgroundColor: 'rgba(48, 48, 48, 0.8)',
        legendBackgroundColorSolid: 'rgb(70, 70, 70)',
        dataLabelsColor: '#444'
    }
};
Sail.widget.ext.ux_chart.themes["dark-blue"] = merge(Sail.widget.ext.ux_chart.themes["grid"], {
    colors: ["#DDDF0D", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee", "#8B8386", "#CD69C9", "#E3CF57", "#303030", "#C67171", "#7D9EC0"],
    chart: {
        backgroundColor: {
            linearGradient: [0, 0, 250, 500],
            stops: [[0, 'rgb(48, 48, 96)'], [1, 'rgb(0, 0, 0)']]
        },
        borderColor: '#000000',
        className: 'dark-container',
        plotBackgroundColor: 'rgba(255, 255, 255, .1)',
        plotBorderColor: '#CCCCCC',
        plotShadow: false
    },
    title: {
        style: {
            color: '#C0C0C0'
        }
    },
    xAxis: {
        gridLineColor: '#333333',
        labels: {
            style: {
                color: '#A0A0A0'
            }
        },
        lineColor: '#A0A0A0',
        tickColor: '#A0A0A0',
        title: {
            style: {
                color: '#C0C0C0'
            }
        }
    },
    yAxis: {
        gridLineColor: '#333333',
        labels: {
            style: {
                color: '#A0A0A0'
            }
        },
        lineColor: '#A0A0A0',
        minorTickInterval: null,
        tickColor: '#A0A0A0',
        title: {
            style: {
                color: '#C0C0C0'
            }
        }
    },
    legend: {
        style: {
            color: '#A0A0A0'
        }
    },
    tooltip: {
        backgroundColor: 'rgba(0, 0, 0, 0.75)',
        style: {
            color: '#F0F0F0'
        }
    },
    toolbar: {
        itemStyle: {
            color: 'silver'
        }
    },
    plotOptions: {
        line: {
            dataLabels: {
                color: '#CCC'
            },
            marker: {
                lineColor: '#333'
            }
        },
        spline: {
            marker: {
                lineColor: '#333'
            }
        },
        scatter: {
            marker: {
                lineColor: '#333'
            }
        }
    },
    legend: {
        itemStyle: {
            color: '#CCC'
        },
        itemHoverStyle: {
            color: '#FFF'
        },
        itemHiddenStyle: {
            color: '#444'
        }
    },
    credits: {
        style: {
            color: '#666'
        }
    },
    labels: {
        style: {
            color: '#CCC'
        }
    },
    legendBackgroundColor: 'rgba(0, 0, 0, 0.5)',
    legendBackgroundColorSolid: 'rgb(35, 35, 70)',
    dataLabelsColor: '#444'
});
Sail.widget.ext.ux_chart.themes["dark-green"] = merge(Sail.widget.ext.ux_chart.themes["dark-blue"], {
    chart: {
        backgroundColor: {
            linearGradient: [0, 0, 250, 500],
            stops: [[0, 'rgb(48, 96, 48)'], [1, 'rgb(0, 0, 0)']]
        }
    }
});
var _THEMES = Sail.widget.ext.ux_chart.themes;

